package com.test.manager;

import java.util.Date;

import org.hibernate.Session;

import com.test.domain.Log;
import com.test.domain.User;
import com.test.util.HibernateUtils;


public class UserManagerImpl  implements UserManager  {

	public void addUser(User user) {
		Session session = null;
		try {
//			session = HibernateUtils.getSession();
			session = HibernateUtils.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			
			session.save(user);
			
			Log log = new Log();
			log.setType("ll");
			log.setTime(new Date());
			log.setDetail("XXX");
			
			LogManager logManager = new LogManagerImpl(); 
			logManager.addLog(log);
			
			Integer.parseInt("1");
			
			session.getTransaction().commit();
		}catch(Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		//}finally {
		//	HibernateUtils.closeSession(session);
		}
	}
	
//	hql.append(" and case when bill.transferTime is null then bill.auditingTime <= ")
//	.append(endTime).append(" when bill.transferTime is not null then (bill.transferTime >= ")
//	
//	.append(endTime).append(" and bill.auditingTime <= ").append(endTime).append(") end ");

	public void loadUser() {
		Session session = null;
		try {
		session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();
//		select c.id  from QuCodeRegion c where case when c.id>'1' then '111' else '333' END='111'
		String sql  =new String(" from User as a  where 1=1 and a.id> case when a.name is null  then 1 end ");
		session.createQuery(sql);
//		session.get(User.class, 0);
		session.getTransaction().commit();
		}catch  (Exception e){
			e.printStackTrace();
			session.getTransaction().rollback();
		}
	}

}
